package com.i360day.invoker;

import org.aopalliance.intercept.MethodInvocation;

import java.lang.reflect.Method;
import java.lang.reflect.Type;

/**
 * 方法源信息
 * @author: liju.z
 * @create: 2021-12-05 17:00
 **/
public class MethodMetadata {

    private transient Type returnType;

    private transient Class<?> returnClazz;
    private transient Method method;
    private transient Object[] args;

    public MethodMetadata(Type returnType, Class<?> returnClazz, Method method, Object[] args) {
        this.returnType = returnType;
        this.returnClazz = returnClazz;
        this.method = method;
        this.args = args;
    }

    public Type getReturnType() {
        return returnType;
    }

    public Class<?> getReturnClazz() {
        return returnClazz;
    }

    public Method getMethod() {
        return method;
    }

    public Object[] getArgs() {
        return args;
    }

    public static MethodMetadata of(MethodInvocation invocation) {
        Method method = invocation.getMethod();
        return new MethodMetadata(method.getReturnType(), method.getReturnType(), method, invocation.getArguments());
    }

    public static MethodMetadata of(Method method, Object [] args) {
        return new MethodMetadata(method.getGenericReturnType(), method.getReturnType(), method, args);
    }
}
